/**
 * 返回年月日
 * @param date
 * @param splicer
 * @returns {string}
 */
export function getDate(date,splicer="-") {
  const year = date.getFullYear()
  const month = date.getMonth()+1
  const day = date.getDate()
  return `${year}${splicer}${addZeroPrefix(month)}${splicer}${addZeroPrefix(day)}`
}

/**
 * 返回时分秒/十分
 * @param date 日期
 * @param withSecond 是否显示秒
 * @returns {string}
 */
export function getTime(date,withSecond = false) {
  const hour = date.getHours();
  const minute = date.getMinutes();
  const second = date.getSeconds()
  return withSecond ? `${addZeroPrefix(hour)}:${addZeroPrefix(minute)}:${addZeroPrefix(second)}`:
    `${addZeroPrefix(hour)}:${addZeroPrefix(minute)}`
}

/**
 * 获取完整的日期
 * @param date
 * @returns {string}
 */
export function getFullDate(date) {
  return `${getDate(date)} ${getTime(date)}`
}


/**
 * 判断指定日期是否为今天
 * @param date
 * @returns {boolean}
 */
export function isToday(date) {
  return date.toDateString() === new Date().toDateString()
}


/**
 * 个位数前面加个0
 * @param number
 * @returns {*}
 */
function addZeroPrefix(number) {
  return number < 10 ? `0${number}`:number
}
